package com.ycsj.goldmedalnewconcept.student.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ycsj.common.utils.DateUtils;
import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.student.bean.DtInfo;

import java.util.List;

/**
 * 道具
 * Created by Administrator on 2019/3/1 0001.
 */

public class DjRvAdapter extends BaseQuickAdapter<DtInfo.DataBean, BaseViewHolder> {
    private List<DtInfo.DataBean> datas;

    public DjRvAdapter(int layoutResId, @Nullable List<DtInfo.DataBean> data) {
        super(layoutResId, data);
        this.datas = data;
    }

    @Override
    protected void convert(BaseViewHolder helper, DtInfo.DataBean item) {
        //月份和日,背景有tv_dj_select和tv_dj_normal
        TextView tvMonthAndDay = helper.getView(R.id.tv_time);

        //获取创建时间
        String currTime = item.getCreate_time();

        if (helper.getLayoutPosition() == 0) {
            //第1个条目的月份和日期显示
            tvMonthAndDay.setVisibility(View.VISIBLE);
            tvMonthAndDay.setText(DateUtils.getTimeStr(currTime, "MM-dd"));
        } else {
            //非第一个条目的聁和日期需要与上一个条目的月份和日期进行比对,如果相同则不显示,不相同则显示
            String beforTime = getData().get(helper.getLayoutPosition() - 1).getCreate_time();

            if (DateUtils.getTimeStr(currTime, "MM-dd").equals(DateUtils.getTimeStr(beforTime, "MM-dd"))) {
                tvMonthAndDay.setVisibility(View.GONE);
            } else {
                tvMonthAndDay.setVisibility(View.VISIBLE);
                tvMonthAndDay.setText(DateUtils.getTimeStr(currTime, "MM-dd"));
            }
        }

        //信息:姓名后接个空格后在拼接内容
        TextView tvContent = helper.getView(R.id.tv_content);
        tvContent.setText(item.getContent());

        //时分
        TextView tvHourAndMiniter = helper.getView(R.id.tv_detail_time);
        tvHourAndMiniter.setText(DateUtils.getTimeStr(currTime, "HH:mm"));

    }

}
